%{

#include "y.tab.h"


int running = 1;
int lineNumber= 1;

#define SYMBOL_UNDEFINED 0
#define SYMBOL_LIT_INTEGER 1
#define SYMBOL_LIT_FLOATING 2
#define SYMBOL_LIT_TRUE 3
#define SYMBOL_LIT_FALSE 4
#define SYMBOL_LIT_CHAR 5
#define SYMBOL_LIT_STRING 6
#define SYMBOL_IDENTIFIER 7

%}

%x COMENT_UMA_LINHA
%x COMENT_MULTIPLAS_LINHAS


DIGIT [0-9]
ALFA [_a-zA-Z]
ALFANUM {ALFA}|{DIGIT}
INTEGER -?{DIGIT}+
CARACTER [^'"\t\n]
ASPAS "\""
WHITESPACE " "|[\t] 
TUDO [.]|[^.]


%%


{INTEGER}				{yylval.symb_tab_node = insert_entry(SYMBOL_LIT_INTEGER, yytext);return LIT_INTEGER;}
{INTEGER}[.]{DIGIT}+			{yylval.symb_tab_node = insert_entry(SYMBOL_LIT_FLOATING, yytext);return LIT_FLOA;}
'({CARACTER}|{ASPAS})'			{yylval.symb_tab_node = insert_entry(SYMBOL_LIT_CHAR, yytext);return LIT_CHAR;}
{ASPAS}({CARACTER}|')*{ASPAS}		{yylval.symb_tab_node = insert_entry(SYMBOL_LIT_STRING, yytext);return LIT_STRING;} 
"true"					{yylval.symb_tab_node = insert_entry(SYMBOL_LIT_TRUE, yytext);return LIT_TRUE;}
"false"					{yylval.symb_tab_node = insert_entry(SYMBOL_LIT_FALSE, yytext);return LIT_FALSE;}  
"<="					{return OPERATOR_LE;}
">="					{return OPERATOR_GE;}    
"=="					{return OPERATOR_EQ;}  
"!="					{return OPERATOR_NE;}  
"&&"					{return OPERATOR_AND;}  
"||"					{return OPERATOR_OR;} 
"int"					{return KW_INT;} 					 
"float"					{return KW_FLOAT;} 					 
"bool"					{return KW_BOOL;} 					 
"char"					{return KW_CHAR;} 					 
"if"					{return KW_IF;} 					 
"then"					{return KW_THEN;} 					 
"else"					{return KW_ELSE;} 					 
"while"					{return KW_WHILE;} 					 
"do"					{return KW_DO;} 					 
"input"					{return KW_INPUT;} 					 
"return"				{return KW_RETURN;} 					 
"output"				{return KW_OUTPUT;} 					 
[-,;:()\[\]{}+*/<>=!&$]			{return yytext[0];}
{ALFA}({ALFA}|{DIGIT})*			{yylval.symb_tab_node = insert_entry(SYMBOL_IDENTIFIER, yytext);return TK_IDENTIFIER;}
"//"					BEGIN(COMENT_UMA_LINHA);
"/*"					BEGIN(COMENT_MULTIPLAS_LINHAS);
[\n]					{lineNumber++;}
{WHITESPACE}				{}
<INITIAL><<EOF>>			{return yytext[0];}
{TUDO}					{return TOKEN_ERROR;}



<COMENT_UMA_LINHA>{

[\n]					{lineNumber++;
					 BEGIN(INITIAL);}
{TUDO}					{}

}


<COMENT_MULTIPLAS_LINHAS>{

"*/"					{BEGIN(INITIAL);}
[\n]					{lineNumber++;}
<<EOF>>					{return TOKEN_ERROR;}
{TUDO}					{}

}


%%


void initMe()
{
	table_initialization();
}

int yywrap()
{
	running = 0;
	return 1;
}


int getLineNumber()
{
	return lineNumber;
}


